/*
	|=====|	|	|
	|	|	|	|
	|=====|	|=====|
	|	|	|	|
	|=====|	|	|
	
	BASEHACK
	Code by "Brwarner" STEAM_0_1_12243023
	
	Library for handling classes for players
*/

//Create table
Class = {};

//Initialize tables
function Class:Init()
	self.players = {};
	self.classes = {};
end

if(SERVER) then

//Called to set a player's class
function Class:SetPlayerClass( ply, class )
	self.players[ply:SteamID()] = class;
end

//Gives the player weapons and health based on their class
function Class:GivePlayerWeapons( ply )
	local cl = self.classes[self.players[ply:SteamID()]];
	ply:StripWeapons();
	ply:RemoveAllAmmo();
	
	for key, val in pairs(cl.weps) do
		ply:Give(val);
	end
	
	ply:RemoveAllAmmo();
	for key, val in pairs(cl.ammos) do
		ply:GiveAmmo(val, key);
	end
	
	ply:SetHealth(cl.health);
end
end

//Gives player more ammo and health
function Class:GivePlayerAmmo( ply )
	local cl = self.classes[self.players[ply:SteamID()]];
	
	ply:RemoveAllAmmo();
	for key, val in pairs(cl.ammos) do
		ply:GiveAmmo(val, key);
	end
	
	local h = ply:Health();
	if(h + 5 > cl.health) then ply:SetHealth(cl.health);
	else ply:SetHealth(h + 5);
	end
end

//Adds a new class to the table
function Class:AddClass(name, weps, amms, health, suit)
	local cl = {};
	cl.weps = weps;
	cl.health = health;
	cl.suit = suit;
	cl.ammos = amms;
	self.classes[name] = cl;
end

//Gets a list of all classes
function Class:GetClassList()
	local names = {};
	local i = 1;
	
	for key, val in pairs(self.classes) do
		names[i] = key;
		i = i + 1;
	end
	return names;
end

//Initiate the library
Class:Init();

//Add default class types
Class:AddClass("Constructor",  {"weapon_crowbar", "weapon_buildgun"}, {}, 75, 0);
Class:AddClass("Soldier", {"weapon_crowbar", "weapon_smg", "weapon_ar2", "weapon_pistol"}, 
	{AR2 = 60, SGM1 = 100, Pistol = 40}, 80, 40 );
Class:AddClass("Hacker", {"weapon_crowbar", "weapon_hacker", "weapon_pistol"}, {Pistol = 50} ,50, 20);
Class:AddClass("Explosive Man", {"weapon_stunstick", "weapon_rpg", "weapon_frag", "weapon_bomb" }, 
	{RPG_Round = 3, Grenade = 3, bombs = 1}, 100, 30 );